package com.gz;
import java.util.Scanner;
public class Test {
    public static void main(String[] args) {
//        IOinfo();
            userRegister();

    }
    public static void userRegister(){
        Scanner scanner= new Scanner(System.in);
        String name;
        String password;
        String email;
        while(true){
            try {
                System.out.println("请输入用户名: ");
                name  = scanner.nextLine();

                System.out.println("请输入密码: ");
                password = scanner.nextLine();
                System.out.println("请输入邮箱: ");
                email = scanner.nextLine();
                check(name,password,email);
                System.out.println("注册成功！！！");
                break;
            } catch (Exception e) {
                System.out.println(e.getMessage());;
            }
        }
    }
    public static void check(String userName, String password, String email) {
        //要求1
        if(!(userName.length()==2||userName.length()==3||userName.length()==4))
            throw new RuntimeException("\n用户名长度不正确，请重新输入");
        //要求2
        if(!(password.length()==6&& isDigital(password)))
            throw new RuntimeException("\n密码输入错误，请重新输入");
        //要求3
        if(email.indexOf("@")==-1||email.indexOf(".")==-1||
                email.indexOf("@")>email.indexOf("."))
            throw new RuntimeException("邮箱格式不对");
    }
    public static boolean isDigital(String password) {
        char[] a =password.toCharArray();
        for(int i=0;i<a.length;i++){
//            if(!(a[i]>='0'&&a[i]<='9'))
            if(Character.isDigit(a[i]))//两种方法都可
                return false;
        }
        return true;
    }
    /*public static void IOinfo(){
        Scanner scanner= new Scanner(System.in);
        int num=0;
        while(true)
        {
            try {
                System.out.println("请输入用户名: ");
                String id = scanner.nextLine();
                if(!(id.length()==2||id.length()==3||id.length()==4))
                    throw new RuntimeException("\n用户名长度不正确，请重新输入");
                System.out.println("请输入密码: ");
                String secret = scanner.nextLine();
                if(secret.length()!=6)
                    throw new RuntimeException("\n密码长度不为6");
                try {
                    num=Integer.parseInt(secret);
                } catch (NumberFormatException e) {
                    throw new NumberFormatException("\n密码格式不对，应该为数字");
                }
                System.out.println("请输入邮箱: ");
                String mail = scanner.nextLine();
                if(mail.indexOf("@")==-1||mail.indexOf(".")==-1||
                        mail.indexOf("@")>mail.indexOf("."))
                    throw new RuntimeException("邮箱格式不对");
            } catch (RuntimeException e) {
                System.out.println(e.getMessage());
            }
            System.out.println("录入正确，注册成功！！");
            break;
        }
    }*/
}


